package com.dlyk.web;

import com.dlyk.model.Permission;
import com.dlyk.result.R;
import com.dlyk.service.PermissionService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 权限
 */
@RestController
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    /**
     * 根据角色id查询权限列表（分页查询）
     */
    @GetMapping("/api/permission/list/{roleId}")
    public R permissionListByRoleId(@PathVariable Integer roleId,
                            @RequestParam(required = false) Integer current) {

        // required = false  表示非必须，这个参数也可以不传，不传参数，默认查询第一页
        if (current == null) {
            current = 1;
        }

        PageInfo<Permission> permissionPageInfo = permissionService.getPermissionListByRoleId(roleId, current);

        return R.OK(permissionPageInfo);
    }

    /**
     * 根据角色id查询未拥有的权限列表
     */
    @GetMapping("/api/permission/notOwned")
    public R permissionList(Integer roleId) {

        List<Permission> permissionList = permissionService.getNotOwnedPermissionList(roleId);

        return R.OK(permissionList);
    }

}

